package TransactionImplementation

import (
	"PaySalary/DataBase"
	"PaySalary/ModelImplementation"
	"PaySalary/TransactionApplication"
	"reflect"
	"time"
)

type ServiceChargeTransaction struct {
	TransactionApplication.Transaction
	itsDate time.Time
	itsCharge float64
	itsMemberId int
}

func (s *ServiceChargeTransaction) NewServiceChargeTransaction(memberId int, date time.Time, charge float64) {
	s.itsMemberId = memberId
	s.itsDate = date
	s.itsCharge = charge
}

func (s *ServiceChargeTransaction) Execute() {
	e := DataBase.PayrollDatabase.GetUnionMember(s, s.itsMemberId)
	af := e.GetItsAffiliation()

	if reflect.TypeOf(af) == reflect.TypeOf(ModelImplementation.UnionAffiliation{}) {
		uaf := af.(*ModelImplementation.UnionAffiliation)
		uaf.AddServiceCharge(s.itsDate, s.itsCharge)
	}
}